package org.goyo.main.domain.entity.pur;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.goyo.main.domain.entity.BaseObject;
import org.goyo.main.domain.entity.base.Supplier;
import org.goyo.main.domain.entity.system.SysUser;
import org.hibernate.type.descriptor.sql.JdbcTypeFamilyInformation.Family;
/**
 * 采购订单
 * 
 * @author chenchuan
 * 2014年11月12日
 */
@Entity
public class PurOrder extends BaseObject implements Serializable {

	private static final long serialVersionUID = 1L;
	
	//单据编号前缀
	public static final String BIZTYPE = "CG";
	/**
	 * 采购类型	
	 */
	@Column
	private String purType;
	/**
	 * 商品规格型号	
	 */
	@Column
	private String standard;
	/**
	 * 供应商	
	 */
	@ManyToOne
	@JoinColumn(name="supplierId")
	private Supplier supplier;
	/**
	 * 采购员	
	 */
	@ManyToOne
	@JoinColumn(name="purPersonId")
	private SysUser purPerson;
	/**
	 * 累计付款金额
	 */
	@Column
	private BigDecimal sumPayAmount = BigDecimal.ZERO;
	
	@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY,mappedBy="purOrder")
	private List<PurOrderEntry> entrys = new ArrayList<PurOrderEntry>();
	
	public String getPurType() {
		return purType;
	}
	public void setPurType(String purType) {
		this.purType = purType;
	}
	public String getStandard() {
		return standard;
	}
	public void setStandard(String standard) {
		this.standard = standard;
	}

	public SysUser getPurPerson() {
		return purPerson;
	}
	public void setPurPerson(SysUser purPerson) {
		if(purPerson != null &&("".equals(purPerson.getUuid()) || purPerson.getUuid()==null))
			this.purPerson = null;
		else
			this.purPerson = purPerson;	
	}
	public List<PurOrderEntry> getEntrys() {
		return entrys;
	}
	public void setEntrys(List<PurOrderEntry> entrys) {
		if(entrys != null){
			for(PurOrderEntry entry : entrys){
				entry.setPurOrder(this);
			}
		}
		this.entrys = entrys;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public Supplier getSupplier() {
		return supplier;
	}
	public void setSupplier(Supplier supplier) {
		if(supplier != null &&("".equals(supplier.getUuid()) || supplier.getUuid()==null))
			this.supplier = null;
		else
			this.supplier = supplier;	
	}
	public BigDecimal getSumPayAmount() {
		return sumPayAmount;
	}
	public void setSumPayAmount(BigDecimal sumPayAmount) {
		this.sumPayAmount = sumPayAmount;
	}
	
}
